<template>
	<view class="ListOfApplicants_box">
		<view class="account_container">
			<view class="account_conatiner_top_bar">
				<view class="" style="margin-right: 20rpx;" @click="goback">
					<image src="../../static/back.png" mode="" style="width: 36rpx;height: 36rpx;"></image>
				</view>
				<view class="">
					报名人员列表
				</view>
			</view>
		</view>
		<view class="account_container_num">

		</view>
		<view class="account_container_detail">
			<view class="uni-padding-wrap uni-common-mt">
				<uni-segmented-control :current="current" :values="items" :style-type="styleType"
					:active-color="activeColor" @clickItem="onClickItem" />
				【新社交体验】与我们来一场活动叭～
			</view>
			<view class="content" style="margin-bottom: 40rpx;">
				<view class="statistics_num">
					<view class="statistics_num_item">
						<view class="statistics_num_item_top">
							{{totalUser}}
						</view>
						<view class="statistics_num_item_bottom">
							总人数
						</view>
					</view>
					<view class="statistics_num_item">
						<view class="statistics_num_item_top">
							{{successUser}}
						</view>
						<view class="statistics_num_item_bottom">
							已付费
						</view>
					</view>
					<view class="statistics_num_item">
						<view class="statistics_num_item_top">
							{{totalUser-successUser}}
						</view>
						<view class="statistics_num_item_bottom">
							待付费
						</view>
					</view>
				</view>
			</view>
			<view class="account_container_detail_pay_user">
				<view class="account_container_detail_pay_user_item" v-for="(item,idnex) in showJoinPeopleList"
					:key="index">
					<view class="account_container_detail_pay_user_left">
						<view class="account_container_detail_pay_user_left_left">
							<img :src="item.avatar" alt="" />
						</view>
						<view class="account_container_detail_pay_user_left_right">
							<view class="account_container_detail_pay_user_left_right_top">
								{{item.userName}}
							</view>
							<view class="account_container_detail_pay_user_left_right_bottom">
								{{item.phone}}
							</view>
						</view>
					</view>
					<view class="account_container_detail_pay_user_right">
						<view class="" v-if="item.orderStatus==1">
							支付中
						</view>
						<view class="" v-if="item.orderStatus==2">
							预支付失败
						</view>
						<view class="" v-if="item.orderStatus==3">
							支付失败
						</view>
						<view class="" v-if="item.orderStatus==4">
							支付成功
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="pagination" v-if="total>10">
			<uni-pagination :total="total" pageSize=10 title="标题文字" @change='paginationChose' />
		</view>
		<button class="btn" @click="exportList">导出名单</button>
	</view>
</template>

<script>
	import {
		showJoinPeople,
		exportApplicantsList,
		accountPeople
	} from "../../api/request.js"
	export default {
		data() {
			return {
				showJoinPeopleList: [],
				activityId: 0,
				pageNo: 1,
				totalUser: 0,
				successUser: 0,
				total: 0
			};
		},
		onLoad(e) {
			this.activityId = e.activityId
			console.log(this.activityId, e);
			this.getData()
		},
		methods: {
			async paginationChose() {
				let res = await showJoinPeople(this.activityId, this.pageNo)
				this.showJoinPeopleList = res.records
				this.total = res.total
			},
			async getData() {
				let res = await showJoinPeople(this.activityId, this.pageNo)
				this.showJoinPeopleList = res.records
				this.total = res.total
				let result = await accountPeople(this.activityId)
				this.successUser = result.successUser
				this.totalUser = result.totalUser
				console.log(res, 'showJoinPeople', result);
			},
			goback() {
				uni.navigateBack()
			},
			async exportList() {
				try {
					let res = await exportApplicantsList(this.activityId); // 假设这个函数返回一个包含数据的响应对象
					console.log('导出结果：', res);

					// 将数据转换为 JSON 字符串
					const jsonData = JSON.stringify(res.data);

					// 获取当前时间
					const currentDate = new Date();

					// 格式化时间字符串，例如：2024-03-25_14-30-00
					const formattedDate =
						`${currentDate.getFullYear()}-${(currentDate.getMonth() + 1).toString().padStart(2, '0')}-${currentDate.getDate().toString().padStart(2, '0')}_${currentDate.getHours().toString().padStart(2, '0')}-${currentDate.getMinutes().toString().padStart(2, '0')}-${currentDate.getSeconds().toString().padStart(2, '0')}`;
					let path = wx.env.USER_DATA_PATH + `/${formattedDate}报名人员.json`
					// 使用小程序的文件系统 API 将数据保存到本地文件
					wx.getFileSystemManager().writeFile({
						filePath: path,
						data: jsonData,
						encoding: 'utf8',
						success: function() {
							console.log('数据已保存到本地文件', path);
							uni.showToast({
								icon: "none",
								title: `保存成功，存放目录：${path}`,
								duration: 5000
							})
						},
						fail: function(error) {
							console.error('保存文件失败：', error);
						}
					});
				} catch (error) {
					// 处理错误情况
					console.error('导出出错：', error);
				}
			}

			// async exportList() {
			// 	let res = await exportApplicantsList(2)
			// 	console.log(res);
			// }
		}
	}
</script>

<style lang="scss">
	.example-body {
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
	}

	.btn-view {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		padding: 15px;
		text-align: center;
		background-color: #fff;
		justify-content: center;
		align-items: center;
	}

	.btn-flex {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
	}

	.button {
		margin: 20px;
		width: 150px;
		font-size: 14px;
		color: #333;
	}

	.btn {
		position: fixed;
		bottom: 58rpx;
		left: 0;
		right: 0;
		width: 90%;
		height: 88rpx;
		background: conic-gradient(from 90deg at 50% 0%, #F09583 0%, #F9301C 100%);
		border-radius: 16rpx;
		margin: auto;

		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 32rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		font-style: normal;
	}

	.uni-common-mt {
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 32rpx;
		color: #1A0200;
		line-height: 44rpx;
		text-align: left;
		font-style: normal;
		margin-left: 20rpx;
	}

	.account_container_detail_pay_user {
		margin-left: 40rpx;

		width: 90%;
		margin: auto;



	}

	.account_container_detail_pay_user_item {
		display: flex;
		justify-content: space-between;
		width: 100%;
		margin-bottom: 60rpx;
	}

	.account_container_detail_pay_user_left {
		display: flex;
		margin-right: 14rpx;

		.account_container_detail_pay_user_left_left image {
			width: 98rpx;
			height: 98rpx;
			border-radius: 50%;
		}

		.account_container_detail_pay_user_left_right {
			display: flex;
			flex-direction: column;
			margin-left: 14rpx;

			.account_container_detail_pay_user_left_right_top {
				margin-top: 12rpx;
				font-family: PingFangSC, PingFang SC;
				font-size: 28rpx;
				color: #1A1A1A;
				line-height: 40rpx;
				text-align: left;
				font-style: normal;
			}

			.account_container_detail_pay_user_left_right_bottom {
				font-family: DINAlternate, DINAlternate;
				font-size: 32rpx;
				color: #000000;
				line-height: 38rpx;
				text-align: left;
				font-style: normal;
			}
		}
	}

	.account_container_detail_pay_user_right {
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #000000;
		line-height: 40rpx;
		text-align: left;
		font-style: normal;
	}

	.statistics_num {
		display: flex;
		text-align: center;
		background: #FFF5F5;
		width: 90%;
		margin: auto;
		height: 160rpx;
		margin-top: 40rpx;

		border-radius: 32rpx;

		.statistics_num_item {
			flex: 1;
			display: flex;
			flex-direction: column;
			margin-top: 24rpx;
			color: white;

			.statistics_num_item_top {
				font-family: DINAlternate, DINAlternate;
				font-weight: bold;
				font-size: 56rpx;
				color: #FA301B;
				line-height: 64rpx;
				font-style: normal;
				margin-bottom: 8rpx;
			}

			.statistics_num_item_bottom {
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #1D1D1D;
				line-height: 40rpx;
				font-style: normal;
			}
		}
	}

	.account_container {
		width: 90%;
		margin: auto;
		margin-top: 88rpx;

		.account_conatiner_top_bar {
			margin-bottom: 20rpx;
			display: flex;
		}
	}

	.account_container_detail_item {
		width: 90%;
		height: 120rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		border: 2rpx solid #F3F3F3;
		display: flex;
		padding-left: 40rpx;
		padding-top: 20rpx;
		margin: auto;
		justify-content: space-between;
		margin-bottom: 20rpx;

		.account_container_detail_item_left {
			display: flex;
			flex-direction: column;
			justify-content: space-around;
		}

		.account_container_detail_item_right {
			margin-top: 36rpx;
			font-family: DINAlternate, DINAlternate;
			font-weight: bold;
			font-size: 36rpx;
			color: #FA301B;
			line-height: 42rpx;
			text-align: left;
			font-style: normal;
			margin-right: 40rpx;
		}
	}

	.account_container_detail {
		margin-top: -60rpx;
		background-color: white;
		border-top-left-radius: 40rpx;
		border-top-right-radius: 40rpx;
	}

	.account_container_num {
		background: url("../../static/people-List/bg1.png") no-repeat 100%;
		background-size: 100% 100%;
		width: 100%;
		height: 432rpx;

		.account_container_num_detail {
			display: flex;
			flex-direction: column;
			margin-left: 80rpx;
			margin-top: 46rpx;

			.item1 {
				margin-top: 46rpx;
				font-family: DINAlternate, DINAlternate;
				font-weight: bold;
				font-size: 48rpx;
				color: #FFFFFF;
				line-height: 56rpx;
				text-align: left;
				font-style: normal;
			}

			.item2 {
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 36rpx;
				color: #FFFFFF;
				line-height: 50rpx;
				text-align: left;
				font-style: normal;
			}

			.item3 {
				font-family: DINAlternate, DINAlternate;
				font-weight: bold;
				font-size: 28rpx;
				color: #FFFFFF;
				line-height: 32rpx;
				text-align: left;
				font-style: normal;
			}

			.item4 {
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #FFFFFF;
				line-height: 40rpx;
				text-align: left;
				font-style: normal;
			}
		}
	}
</style>